package jukebox.model.freecomment;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import jukebox.model.common.BoardVO;
import jukebox.model.common.CommentVO;
import jukebox.model.common.ListVO;
import jukebox.model.common.PagingBean;

import org.springframework.stereotype.Service;
@Service
public class FreeCommentServiceImpl implements FreeCommentService {

	@Resource(name="freeCommentDAOImpl")
	private FreeCommentDAO freeCommentDAO;
	
	@Override
	public void freeWriteComment(CommentVO cvo) {
		freeCommentDAO.freeWriteComment(cvo);
	}
	
	@Override
	public ListVO<CommentVO> freeFindCommentListByBoardNo(int no,int nowPage) {
		ListVO vo = null;		
		//PagingBean을 생성해준다.
				//boardDAO.freeCommentCount() 전체 댓글 수
				//현재 페이지 nowPage
				PagingBean pb = new PagingBean(freeCommentDAO.freeCommentCount(no),nowPage);//int totalContents, int nowPage
		//현재페이지에 맞는 게시물정보를 가져온다.
				//System.out.println(pb);
				HashMap map=new HashMap();
				map.put("numberOfContentsPerPage", pb.getNumberOfContentsPerPage());
				map.put("boardNo",no);
				map.put("nowPage", pb.getNowPage());
				
		List<CommentVO> list = freeCommentDAO.freeFindCommentListByBoardNo(map); //page에 해당하는댓글들을 조회
		System.out.println(list);
		vo = new ListVO(list,pb);//List<CommentVO> list, PagingBean pagingBean
		
		return vo;

	}

	@Override
	public void freeUpdateComment(CommentVO cvo) {
		freeCommentDAO.freeUpdateComment(cvo);		
	}

	@Override
	public void freeDeleteComment(int no) {
		freeCommentDAO.freeDeleteComment(no);		
	}

	

}
